function toggleView(event)
{
	var view = parseInt($(event.target).text(), 10);
	
	View.views[view].setHidden(!View.views[view].hidden);
	
	$(event.target).toggleClass('selected');
	
	$(document).trigger('close.facebox');
	
	event.stopPropagation();
}

function viewsSetHiddenAll(hidden)
{
	jQuery.each(
		View.views, function()
		{
			this.setHidden(hidden);
		});
	
	$(document).trigger('close.facebox');
}

$(function() {
	// View enabler/disabler
	var selector = '';
	jQuery.each(
		View.views, function(i)
		{
			selector += 
				'<span onclick="toggleView(event)" class="clickable'
					+ (this.hidden ? '' : ' selected')
					+ '">' + i
				+ '</span>';
		});
	
	$('#viewSelector').html(selector);
	
	// Check if all views are visible or hidden
	var someVisible = false, someHidden = false;
	jQuery.each(
		View.views, function()
		{
			if (this.hidden) {
				someHidden = true;
			} else {
				someVisible = true;
			}
		});
	
	$('#viewsShowAll, #viewsHideAll').removeClass('selected');
	
	if (!someVisible) {
		// All are hidden
		$('#viewsHideAll').addClass('selected');
	} else if (!someHidden) {
		// All are visible
		$('#viewsShowAll').addClass('selected');
	}
});